package com.example.mall.service.impl;

import com.example.mall.mbg.mapper.CustomIndicatorMapper;
import com.example.mall.mbg.mapper.IndicatorMapper;
import com.example.mall.mbg.model.Indicator;
import com.example.mall.mbg.model.IndicatorExample;
import com.example.mall.service.IndicatorService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * IndicatorServiceImpl
 * Created by on 2023/12/27.
 */
@Service
public class IndicatorServiceImpl implements IndicatorService {
    @Autowired
    private IndicatorMapper indicatorMapper;
    @Autowired
    private CustomIndicatorMapper customIndicatorMapper;

    @Override
    public List<Indicator> listAll() {
        return indicatorMapper.selectByExample(new IndicatorExample());
    }

    @Override
    public int create(Indicator indicator) {
        return indicatorMapper.insertSelective(indicator);
    }

    @Override
    public int update(Integer indicatorid, Indicator indicator) {
        indicator.setIndicatorid(indicatorid);
        return indicatorMapper.updateByPrimaryKeySelective(indicator);
    }

    @Override
    public int delete(Integer indicatorid) {
        return indicatorMapper.deleteByPrimaryKey(indicatorid);
    }

    @Override
    public List<Indicator> list(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return indicatorMapper.selectByExample(new IndicatorExample());
    }

    @Override
    public Indicator get(Integer indicatorid) {
        return indicatorMapper.selectByPrimaryKey(indicatorid);
    }

    @Override
    public int getNextId() {
        return customIndicatorMapper.getNextId();
    }

    @Override
    public Indicator getIndicatorByName(String indicatorName) {
        return customIndicatorMapper.getIndicatorByName(indicatorName);
    }
}
